package fr.insalyon.sims.broadcast.tests;

import java.awt.Dimension;

import javax.swing.JFrame;

import fr.insalyon.sims.broadcast.network.DataErrorEvent;
import fr.insalyon.sims.broadcast.network.DataErrorListener;
import fr.insalyon.sims.broadcast.network.TCPStreamReceiver;
import fr.insalyon.sims.broadcast.tools.DisplayPanel;
import fr.insalyon.sims.broadcast.tools.ImageBuilder;

public class TCPImageTest {
	// ------------------------------------------------------- CONSTANTS -- //
	// ------------------------------------------------------ ATTRIBUTES -- //
	// ---------------------------------------------------- CONSTRUCTORS -- //
	// --------------------------------------------------------- METHODS -- //
	
	public static void main(String[] args) {
		int destPort = 22593;
		
		ImageBuilder builder = new ImageBuilder();
		
		DisplayPanel panel = new DisplayPanel(builder);
		panel.start();
		
		JFrame frame = new JFrame("wOOt");
		frame.add(panel);
		frame.setSize(new Dimension(600, 500));
		frame.setVisible(true);
		
		// Create TCP receiver stream
		TCPStreamReceiver receiver = new TCPStreamReceiver(destPort);
		receiver.addDataListener(builder);
		receiver.addDataErrorListener(new DataErrorListener() {
			public void streamError(DataErrorEvent event) {
				System.out.println("[receiver] an exception occured!");
				event.getException().printStackTrace();
			}
		});
		
		// Start the stream
		receiver.connect();
		receiver.start();
	}
	
	// ------------------------------------------------- PRIVATE METHODS -- //
	// --------------------------------------------------- INNER CLASSES -- //
}

